Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

precise-typeof

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

precise-typeof

Better 'typeof'. Detects real type of the objects like 'Array()', 'new Number(1)', 'new Boolean(true)', etc.

  • 1.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
823
increased by4.97%
Maintainers
1
Weekly downloads
 
Created
Source

precise-typeof NPM Module

Better typeof. Detects real type of the objects like Array(), new Number(1), new Boolean(true), etc.

PhantomJS Build Linux Build Windows Build

Coverage Status Dependency Status bitHound Overall Score

compressionsize
precise-typeof.js2.35 kB
precise-typeof.min.js1.41 kB
precise-typeof.min.js.gz639 B

Install

$ npm install precise-typeof --save

Examples

var typeOf = require('precise-typeof');

typeOf({});               // -> 'object'
typeOf(new function(){}); // -> 'object'
typeOf([]);               // -> 'array'
typeOf(25);               // -> 'number'
typeOf(Infinity);         // -> 'number'
typeOf('ABC');            // -> 'string'
typeOf(function(){});     // -> 'function'
typeOf(Math.sin);         // -> 'function'
typeOf(undefined);        // -> 'undefined'
typeOf(true);             // -> 'boolean'
typeOf(null);             // -> 'null'
typeOf(NaN);              // -> 'nan'

// object values
typeOf(new Object());                           // -> 'object'
typeOf(new Array());                            // -> 'array'
typeOf(new Number(5));                          // -> 'number'
typeOf(new Number(Infinity));                   // -> 'number'
typeOf(new String('ABC'));                      // -> 'string'
typeOf(new Function('a', 'b', 'return a + b')); // -> 'function'
typeOf(new Boolean());                          // -> 'boolean'
typeOf(new Number('blabla'));                   // -> 'nan'

// special objects
typeOf(/s/);         // -> 'regexp'
typeOf(new Date());  // -> 'date'
typeOf(Math);        // -> 'math'
typeOf(new Error()); // -> 'error'
typeOf(arguments);   // -> 'arguments'

// node
typeOf(global);               // -> 'global'
typeOf(process);              // -> 'process'
typeOf(Buffer('B'));          // -> 'buffer'
typeOf(new Buffer(2));        // -> 'buffer'
typeOf(Buffer([62, 64, 66])); // -> 'buffer'

// es6
typeOf(Symbol('A')); // -> 'symbol'

// browser
typeOf(window);                                   // -> 'global'
typeOf(document);                                 // -> 'html'
typeOf(document.body);                            // -> 'html'
typeOf(document.getElementsByTagName('html')[0]); // -> 'html'
typeOf(document.getElementsByTagName('div'));     // -> 'html'
typeOf(document.createElement('a'));              // -> 'html'
typeOf(document.createTextNode('Abcd'));          // -> 'text'
typeOf(document.createComment('abcd'));           // -> 'comment'
typeOf(document.createEvent('Event'));            // -> 'event'
typeOf(document.createEvent('UIEvents'));         // -> 'event'
typeOf(document.createEvent('HTMLEvents'));       // -> 'event'
typeOf(document.createEvent('MouseEvents'));      // -> 'event'

License

Precise-TypeOf is licensed under the MIT license.

Keywords

FAQs

Package last updated on 16 Mar 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc